package com.njwb.day15.zqzb.method.dyc;

import com.njwb.day15.zqzb.method.proxy.RealSubject;
import com.njwb.day15.zqzb.method.proxy.Subject;

import java.util.ArrayList;
import java.util.List;

public class Test {
    public static void main(String[] args) {
        //创建一个调用处理器
        MyInvocationHandler myInvocationHandler = new MyInvocationHandler(new RealSubject("黄世仁"));
        //得到代理对象
        Object object = myInvocationHandler.getProxy();
        //属于subject的实例
        System.out.println(object instanceof  Subject);
        //转型
        Subject proxy  = (Subject) object;

        //proxy去调用方法。
        proxy.getMoney();
        System.out.println("------------------------------------------------");

        ArrayList  arrayList = new ArrayList<>();
        //换掉真实对象
        myInvocationHandler.setObj(arrayList);
        //获取代理对象
       object = myInvocationHandler.getProxy();

        System.out.println(object instanceof List);
        List proxy2 = (List) object;

        proxy2.add("Node");
        proxy2.add("b");
        proxy2.add("c");

        proxy2.add("d");

        proxy2.add("e");
        proxy2.add("f");
        proxy2.add("g");
        proxy2.add("h");

        System.out.println(arrayList);

    }
}
